package com.puzzlebazar.client.util;

import java.util.EnumMap;

import com.puzzlebazar.client.puzzleinfo.PuzzleInfo.Status;
import com.puzzlebazar.client.puzzleinfo.PuzzleInfo.Validity;

public class EnumToString {

	private static final EnumMap<Validity,String> validityMap 
		= new EnumMap<Validity,String>(Validity.class);

	private static final EnumMap<Status, String> statusMap
		= new EnumMap<Status,String>(Status.class);

	/**
	 * Return the string for an element of the Validity enum
	 * 
	 * @param validity An element of the Validity enum
	 * @return The nice string for this element
	 */
	public static String get( Validity validity ) {
		if( validityMap.isEmpty() ) 
			fillValidityMap();
		final String result = validityMap.get( validity );
		if( result == null ) return validity.toString();
		return result;
	}


	/**
	 * Fill the validity map with nice strings.
	 */
	private static void fillValidityMap() {
		validityMap.put(Validity.UNKNOWN, "Validity unknown" );
		validityMap.put(Validity.SOLUTION_UNKNOWN, "Invalid, no known solution" );
		validityMap.put(Validity.NO_SOLUTION, "Invalid, no solution" );
		validityMap.put(Validity.ONE_SOLUTION, "Valid, at least one solution exists" );
		validityMap.put(Validity.UNIQUE_SOLUTION, "Valid, exactly one solution exists" );
		validityMap.put(Validity.MULTIPLE_SOLUTIONS, "Invalid, multiple solutions" );
	}


	/**
	 * Return the string for an element of the Status enum
	 * 
	 * @param validity An element of the Status enum
	 * @return The nice string for this element
	 */
	public static String get(Status status) {
		if( statusMap.isEmpty() ) 
			fillStatusMap();
		final String result = statusMap.get( status );
		if( result == null ) return status.toString();
		return result;
	}

	/**
	 * Fill the validity map with nice strings.
	 */
	private static void fillStatusMap() {
		statusMap.put(Status.UNKNOWN, "Status unknown" );
		statusMap.put(Status.PRIVATE, "Not published" );
		statusMap.put(Status.PUBLISHED, "Published without review" );
		statusMap.put(Status.IN_REVIEW, "Being reviewed" );
		statusMap.put(Status.ACCEPTED, "Accepted for publication" );
		statusMap.put(Status.REVIEW_PUBLISHED, "Published with review" );
	}
	
}
